#include "Grid.h"

#include <algorithm>
#include "Simulation.h"
#include "GlobalConst.h"

CGrid::CGrid() :
  m_Matrix()
{
  float CellWidth  = 50;
  float CellHeight = 50;

  CCell::SetWidth (CellWidth);
  CCell::SetHeight(CellHeight);

  int rows    = 7;
  int columns = 20;

  for (int i = 0; i < rows; ++i)
  {
    std::vector<CCell> row;
    for (int j = 0; j < columns; ++j)
      row.push_back(CCell(CellWidth * j, CellHeight * i, CCell::Seat));
    
    m_Matrix.push_back(row);
  }

  for (int i = 0; i < columns; ++i)
    m_Matrix[rows / 2][i].SetCellType(CCell::Empty);

  m_Matrix[rows - 1][columns - 1].SetCellType(CCell::Exit);
}

CGrid::~CGrid()
{
}

void CGrid::Render()
{
  /*
  HGE * hge = CSimulation::GetInstance()->GetHGEObject();

  int rows    = m_Matrix.size();
  int columns = m_Matrix[0].size();

  float stepX = SCREEN_WIDTH  / columns;
  float stepY = SCREEN_HEIGHT / rows;

  for (int i = 0; i < rows; ++i)
    hge->Gfx_RenderLine(0, i * stepY, SCREEN_WIDTH, i * stepY);

  for (int i = 0; i < columns; ++i)
    hge->Gfx_RenderLine(i * stepX, 0, i * stepX, SCREEN_HEIGHT);
  */

  std::for_each(m_Matrix.begin(), m_Matrix.end(), [](std::vector<CCell> row) {
      std::for_each(row.begin(), row.end(), [](CCell Cell) {
          Cell.Render();
        });
    });
}

void CGrid::Update(
    float _TimeDelta
  )
{
}
